<template>
  <!-- 遮罩层 -->
  <view v-if="visible" class="modal-mask" @tap="closeModal">
    <!-- 模态框内容 -->
    <view class="modal-container" @tap.stop>
      <view class="modal-header">
        <text class="modal-title">{{ title }}</text>
      </view>
      <view class="modal-body">
        <slot></slot>
      </view>
      <view class="modal-footer">
        <button @tap="closeModal" style="padding: 0 80rpx; background-color: #39cd80; color: #fff;">关闭</button>
        <!-- <button @tap="confirm" style="background-color: #39cd80; color: #fff; padding: 0 45rpx;">开通会员</button> -->
      </view>
    </view>
  </view>
</template>

<script lang="ts">
import { defineComponent } from 'vue';

export default defineComponent({
  name: 'Modal',
  props: {
    visible: {
      type: Boolean,
      required: true
    },
    title: {
      type: String,
      default: '正在开发中……'
    }
  },
  emits: ['update:visible', 'confirm'],
  setup(props, { emit }) {
    const closeModal = () => {
      emit('update:visible', false);
    };
    
    const confirm = () => {
      emit('confirm');
      closeModal();
    };
    
    return {
      closeModal,
      confirm
    };
  }
});
</script>

<style scoped>
.modal-mask {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 999;
}

.modal-container {
  width: 80%;
  background-color: #fff;
  border-radius: 10px;
  overflow: hidden;
}

.modal-header {
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 34rpx;
  padding: 60rpx 0 30rpx 0;
}

.modal-title {
  display: flex;
  justify-content: center;
}

.modal-body {
  padding-bottom: 50rpx;
  text-align: center;
  font-size: 32rpx;
  color: #aaa;
}

.modal-footer {
  padding-bottom: 60rpx;
  display: flex;
  justify-content: space-around;
}

.modal-footer button {
	font-size: 32rpx;
}
</style>